<script setup lang="ts">
import { ref } from 'vue'

import ItemWrap from "@/components/item-wrap";
import LeftTop from "./left-top.vue";
import LeftCenter from "./left-center.vue";
import LeftBottom from "./left-bottom.vue";
// import CenterMap from "./center-map.vue";
import CenterMap from "./centerMapVice.vue";
// import CenterMap from "./mapTest.vue";
import CenterBottom from "./center-bottom.vue";
import RightTop from "./right-top.vue";
import RightCenter from "./right-center.vue";
import RightBottom from "./right-bottom.vue";
import CenterNavTop from "./center-navTop.vue";
import NavPage from "@/components/navPage/index.vue";
import MapContainer from "./MapContainer.vue";

const CenterMapRef = ref<InstanceType<typeof CenterMap>>()
const CenterNavTopRef = ref<InstanceType<typeof CenterNavTop>>()
const RightCenterRef = ref<InstanceType<typeof RightCenter>>()
const LeftCenterRef = ref<InstanceType<typeof LeftCenter>>()
const LeftBottomRef = ref<InstanceType<typeof LeftBottom>>()
const RightTopRef = ref<InstanceType<typeof RightTop>>()


const LeftTopRef = ref<InstanceType<typeof LeftTop>>()
const handleNavChange = (index: number, item: any) => {
    console.log(index, item);
}

import { getDataInfo } from "@/api/port";
import { onMounted } from "vue";
const dataInfo = ref<any>({})
onMounted(() => {
  getDataInfo({type: 0}).then((res) => {
    console.log(res);
    dataInfo.value = res.data
    if (LeftTopRef.value) {
        LeftTopRef.value.getProgressData(res.data.module1)
    }
    
    
    

    if (CenterNavTopRef.value) {
        CenterNavTopRef.value.getNavData(res.data.module4)
    }

    if (CenterMapRef.value) {
        CenterMapRef.value.getPointTypeData(res.data.module8)
        CenterMapRef.value.getPointData(res.data.module5)
    }
    
    if (LeftCenterRef.value) {
        LeftCenterRef.value.getData(res.data.module6)
    }

    if (LeftBottomRef.value) {
        LeftBottomRef.value.getData(res.data.module3)
    }
  });
  getDataInfo({type: 3}).then((res) => {
    console.log(res);
    if (RightTopRef.value) {
        let obj = JSON.parse(res.data.module5)

        RightTopRef.value.getData(JSON.stringify({
            malfunction: obj.fault,
            batterySwap: obj.swap,
            waitingsharedTravel: obj.waitRent,
            insharedTravel: obj.rent,
        }))
    }
  });
  getDataInfo({type: 4}).then((res) => {
    console.log(res);
    if (RightCenterRef.value) {
        RightCenterRef.value.getData(res.data.module1)
    }
  });
});


</script>

<template>
    <div class="index-box">
        <div class="contetn_left">
            <!-- <div class="pagetab">
                <div class="item">实时监测</div>
                <div class="item">统计分析</div>
            </div> -->
            <ItemWrap class="contetn_left-top contetn_lr-item" title="绿电供应" style="flex: 1;">
                <LeftTop ref="LeftTopRef" :data="dataInfo" />

            </ItemWrap>
            <!-- <ItemWrap class="contetn_left-bottom contetn_lr-item" title="实际发电指标" style="flex: 1;">
                <RightBottom />
            </ItemWrap> -->
            <ItemWrap class="contetn_left-bottom contetn_lr-item" title="共享出行" style="flex: 1;">
                <RightTop style="width: 100%;height: 100%;" ref="RightTopRef"/>

            </ItemWrap>
            <!-- <ItemWrap
                class="contetn_left-bottom contetn_lr-item"
                title="数据统计"
                style="flex: 1;"
            >
                <LeftBottom />
            </ItemWrap> -->
            
            <ItemWrap class="contetn_left-bottom contetn_lr-item" title="共享运力" style="flex: 1;">
                <RightCenter ref="RightCenterRef"/>

            </ItemWrap>
        </div>
        <div class="contetn_center">
            <CenterNavTop ref="CenterNavTopRef" />
            <CenterMap class="contetn_center_top" title="分布图" ref="CenterMapRef" />

            <!-- <MapContainer class="contetn_center_top"></MapContainer> -->
            <NavPage @nav-change="handleNavChange" :nav-index="2" />
            <!-- <ItemWrap class="contetn_center-bottom" title="安装计划">
                <CenterBottom />
            </ItemWrap> -->
        </div>
        <div class="contetn_right">
            <!-- <ItemWrap class="contetn_left-bottom contetn_lr-item" title="共享出行">
                <RightTop />
            </ItemWrap>
            <ItemWrap class="contetn_left-bottom contetn_lr-item" title="共享运力">
                <RightCenter />
            </ItemWrap> -->
            <ItemWrap class="contetn_left-center contetn_lr-item" title="共享换电" style="flex: 2;">
                <!-- height: 415px;  -->
                <LeftCenter ref="LeftCenterRef"/>

            </ItemWrap>
            <ItemWrap
                class="contetn_left-bottom contetn_lr-item"
                title="数据统计"
                style="flex: 1;"
            >
                <LeftBottom ref="LeftBottomRef"/>

            </ItemWrap>
        </div>
    </div>
</template>

<style scoped lang="less">
.index-box {
    width: 100%;
    display: flex;
    min-height: calc(100% - 64px);
    justify-content: space-between;
}

//左边 右边 结构一样
.contetn_left,
.contetn_right {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    position: relative;
    width: 540px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.contetn_center {
    flex: 1;
    // margin: 0 54px;
    display: flex;
    flex-direction: column;

    // justify-content: space-around;
    .contetn_center-bottom {
        height: 315px;
    }

    .contetn_center_top {
        flex: 1;
    }
}

.contetn_lr-item {
    height: 310px;
}
</style>
